<?php

use yii\db\Migration;

class m000000_000013_create_user_account_log extends Migration
{
    public function up()
    {
        $this->createTable('{{%user_account_log}}', [
            'id'=>$this->primaryKey(), // PK
            'uid'=>$this->integer(), // 用户编号
            'type'=>$this->integer(), // 类型
            'money'=>$this->decimal(12, 2), // 现金
            'freeze_money'=>$this->decimal(12, 2), // 冻结现金
            'score'=>$this->integer(), // 消费积分
            'point'=>$this->integer(), // 等级积分
            'time'=>$this->integer(), // 时间
            'info'=>$this->text(), // 备注
        ]);
        $this->createIndex('fk_user_account_log_user1_idx', '{{%user_account_log}}', ['uid']);
        try {
            $this->addForeignKey('fk_user_account_log_user1', '{{%user_account_log}}', ['uid'], '{{%user}}', ['id']);
        } catch (Exception $e) {
        }
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['user_account_log_type', 1, '现金'],
            ['user_account_log_type', 2, '冻结现金'],
            ['user_account_log_type', 4, '消费积分'],
            ['user_account_log_type', 8, '等级积分'],
        ]);
    }

    public function down()
    {
        $this->dropTable('{{%user_account_log}}');
        $this->delete('{{%key_map}}', ['t'=>'user_account_log_type']);
    }
}
